<?php

namespace Xrfg\Api\Trading\Home\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
use Xrfg\Api\Trading\Home\Console\Commands\CNY;

class ServiceProvider extends IlluminateServiceProvider
{
    public function boot()
    {
        $this->registerMigrations();
        $this->registerRoutes();
        $this->registerCommands();
    }

    public function register()
    {
        $this->mergeConfigFrom(
            __DIR__.'/../../config/error.php',
            'error'
        );
    }

    private function registerMigrations()
    {
        if ($this->app->runningInConsole()) {
            $this->loadMigrationsFrom(__DIR__.'/../../migrations');
        }
    }

    private function registerRoutes()
    {
        Route::prefix('api/home')
            ->middleware('api')
            ->namespace('Xrfg\\Api\\Trading\\Home\\Controllers')
            ->group(function () {
                $this->loadRoutesFrom(__DIR__.'/../../routes/api.php');
            });
    }

    private function registerCommands()
    {
        if ($this->app->runningInConsole()) {
            $this->commands([
                CNY::class,
            ]);
        }
    }
}
